﻿package com.zit.service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.zit.dao.ProfessionDAO;
import com.zit.entity.Profession;

/**
 * 功能：专业管理
 * 
 * @author 唐美兰
 * @createTime 2013-12-3
 */
public class ProfessionService extends BaseService {

	private ProfessionDAO professiondao = new ProfessionDAO();

	/**
	 * 功能：查詢所有专业
	 * 
	 * @return
	 */
	public List<Profession> showprofession() {
		List<Profession> list = super.findAll(Profession.class);
		return list;
	}

	/**
	 * 功能：添加专业
	 * @param p
	 */
	public void addprofession(Profession p) {
		super.save(p);
	}
	
	/**
	 * 功能：修改专业名
	 * @param p
	 */
	public void updateprofession(Profession p){
		Session s = null;
		Transaction tx = null ;
		try {
			s = getSession();
			tx = s.beginTransaction();
			professiondao.updateprofession(s, p.getName(),p.getId());
			tx.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			s.close();
		}
	}

}
